@media print {
    /* Reset page setup */
    @page {
        margin: 0.5cm;
        size: auto;
    }

    /* Hide UI elements */
    .toolbar,
    .sidebar,
    .hamburger,
    .breadcrumbs,
    .footer,
    .copy-button,
    .file-attachments-section,
    .editor-container,
    .comments-section,
    .comment-form,
    .comments-list,
    .search-results,
    .dialog-container,
    .login-dialog,
    .file-upload-dialog,
    .new-document-dialog,
    .move-document-dialog,
    .confirmation-dialog,
    .message-dialog,
    .user-confirmation-dialog,
    .version-history-dialog,
    .settings-dialog,
    .password-warning-banner,
    .page-toolbar {
        display: none !important;
    }

    /* Fix height issues that cause blank pages */
    html, body {
        height: auto !important;
        min-height: 0 !important;
        width: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        position: static !important;
        display: block !important;
    }

    /* Content layout - remove fixed heights */
    .content {
        margin: 0 !important;
        padding: 12px !important;
        width: 100% !important;
        max-width: none !important;
        min-height: 0 !important;
        height: auto !important;
        position: static !important;
        display: block !important;
        overflow: visible !important;
    }

    /* Fix for elements with min-height that can cause blank pages */
    .markdown-content {
        min-height: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* Reduce margins to prevent unnecessary page breaks */
    .content > * {
        margin-bottom: 0.5em !important;
        margin-top: 0.5em !important;
        overflow: visible !important;
    }

    /* The rest of the print styles */
    .content h1 {
        margin-bottom: 0.75em !important;
    }

    .content h2 {
        margin-top: 1.25em !important;
        margin-bottom: 0.5em !important;
        padding-bottom: 0.25em !important;
    }

    .content h3 {
        margin-top: 1em !important;
        margin-bottom: 0.5em !important;
    }

    /* Text elements spacing */
    .content p {
        margin: 0.4em 0 1.2em 0 !important;
        orphans: 3;
        widows: 3;
    }

    .content ul, .content ol {
        margin: 0.4em 0 !important;
        padding-left: 1.25em !important;
    }

    .content li {
        margin: 0.2em 0 !important;
    }

    /* Block elements */
    .content pre {
        padding: 8px !important;
        margin: 0.5em 0 !important;
        max-width: 100% !important;
        border-radius: 0 !important;
    }

    .content blockquote {
        margin: 0.5em 0 !important;
        padding: 0.4em 0.75em !important;
    }

    /* Ensure all text is black in print */
    .content p,
    .content ul,
    .content ol,
    .content li,
    .content table,
    .content td,
    .content th,
    .content blockquote,
    .content h1,
    .content h2,
    .content h3,
    .content h4,
    .content h5,
    .content h6 {
        color: black !important;
    }

    /* Code block styles */
    pre, pre[class*="language-"] {
        background: none !important;
        border: 1px solid #ccc !important;
        page-break-inside: avoid !important;
        max-width: 100% !important;
        font-size: 11pt !important;
        line-height: 1.4 !important;
        padding: 15px !important;
        margin: 20px 0 !important;
        overflow: visible !important;
        box-shadow: none !important;
        white-space: pre-wrap !important;
        word-wrap: break-word !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }

    /* Code elements */
    code, code[class*="language-"],
    pre code, pre[class*="language-"] code,
    :not(pre) > code {
        background: #f0f0f0 !important;
        color: black !important;
        padding: 2px 4px !important;
        font-family: "Courier New", Courier, monospace !important;
        white-space: pre-wrap !important;
        word-wrap: break-word !important;
    }

    pre > code {
        border: none !important;
    }

    /* Mermaid diagram print styles - force light theme */
    .mermaid {
        background-color: white !important;
    }

    .mermaid svg {
        background-color: white !important;
        filter: none !important;
    }

    /* All mermaid SVG elements */
    .mermaid svg rect,
    .mermaid svg polygon,
    .mermaid svg circle,
    .mermaid svg ellipse,
    .mermaid svg path,
    .mermaid svg .node rect,
    .mermaid svg .node circle,
    .mermaid svg .node ellipse,
    .mermaid svg .node polygon,
    .mermaid svg .cluster rect {
        fill: white !important;
        stroke: black !important;
    }

    /* All mermaid text elements */
    .mermaid svg .label,
    .mermaid svg text,
    .mermaid svg .edgeLabel {
        color: black !important;
        fill: black !important;
    }

    .mermaid svg .edgeLabel {
        background-color: white !important;
    }

    .mermaid svg .edgePath .path {
        stroke: black !important;
    }

    /* Task list checkboxes */
    .task-checkbox {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        box-shadow: inset 0 0 0 2px #000 !important;
        background-color: white !important;
        width: 14px !important;
        height: 14px !important;
        border: none !important;
        position: relative !important;
        border-radius: 2px !important;
        margin-top: 3px !important;
    }

    .task-checkbox:checked {
        background-color: #000 !important;
        box-shadow: none !important;
    }

    .task-checkbox:checked::after {
        content: "" !important;
        position: absolute !important;
        top: 1px !important;
        left: 4px !important;
        width: 3px !important;
        height: 7px !important;
        border: solid white !important;
        border-width: 0 2px 2px 0 !important;
        transform: rotate(45deg) !important;
        display: block !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Task list indentation */
    .task-list-item-container[data-indent-level="1"] {
        margin-left: 1.5rem !important;
    }

    .task-list-item-container[data-indent-level="2"] {
        margin-left: 3rem !important;
    }

    .task-list-item-container[data-indent-level="3"] {
        margin-left: 4.5rem !important;
    }

    .task-list-item-container[data-indent-level="4"] {
        margin-left: 6rem !important;
    }

    .task-list-item-container[data-indent-level="5"] {
        margin-left: 7.5rem !important;
    }

    /* Syntax highlighting for print - all tokens to black */
    .token.comment,
    .token.string,
    .token.number,
    .token.keyword,
    .token.function,
    .token.boolean,
    .token.operator,
    .token.punctuation {
        color: black !important;
        background-color: #f0f0f0 !important;
    }

    /* Add font weight for some tokens for better distinction */
    .token.keyword,
    .token.boolean {
        font-weight: bold !important;
    }

    .token.comment {
        font-style: italic !important;
    }

    /* Page break rules */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }

    img, table {
        page-break-inside: avoid;
    }

    /* Link styling */
    a {
        text-decoration: underline !important;
        color: #000066 !important;
    }

    /* Special elements */
    .content mark {
        background-color: #f0f0f0 !important;
        color: black !important;
        border: 1px solid #ccc !important;
    }

    .content del {
        text-decoration: line-through !important;
        color: black !important;
        opacity: 0.7 !important;
    }

    /* Footnotes */
    .footnotes {
        border-top: 1px solid #ccc !important;
        color: black !important;
    }

    .footnote-ref,
    .footnote-backref {
        color: black !important;
    }
}